//
//  BHeapLC.swift
//  DataStructureAndAlgorithm
//
//  Created by icemelon on 2021/9/22.
//

import Foundation

func topK<T: Comparable>(data: [T], k: Int) -> BinaryHeap<T> {
    let h = BinaryHeap<T>(type: .Min)
    for item in data {
        if h.size < k {
            h.add(element: item)
        }
        else {
            if item > h.get()! {
                h.replace(element: item)
            }
        }
    }
    return h
}
